package com.enn.demo.application;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.enn.demo.application.assembler.RoleDTOAssembler;
import com.enn.demo.client.RoleQueryService;
import com.enn.demo.client.common.PageUtil;
import com.enn.demo.client.dto.RoleDTO;
import com.enn.demo.core.domain.shared.enums.StatusEnum;
import com.enn.demo.core.domain.model.role.RoleId;
import com.enn.demo.core.domain.repository.RoleRepository;
import com.enn.demo.application.assembler.PageAssembler;
import com.enn.demo.dal.entity.SysRoleDO;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色查询服务实现类
 *
 * @author haoxin
 * @date 2021-05-10
 **/
@Service
public class RoleQueryServiceImpl implements RoleQueryService {

    @Autowired
    private RoleRepository roleRepository;

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<SysRoleDO> page = roleRepository.queryPage(params);
        return PageAssembler.toPage(page);
    }

    @Override
    public List<RoleDTO> listAll() {
        HashMap<String, Object> param = Maps.newHashMap();
        param.put("status", StatusEnum.ENABLE.getValue());
        return RoleDTOAssembler.getRoleDTOList(roleRepository.queryList(param));
    }

    @Override
    public RoleDTO getById(String id) {
        return RoleDTOAssembler.fromRole(roleRepository.find(new RoleId(id)));
    }
}
